SUBROUTINE utilfun(pconsin,ELNqconsin,thetain,utilout)

  USE commonvars
  IMPLICIT NONE

  REAL(8), INTENT(IN)  :: pconsin, ELNqconsin, thetain
  REAL(8), INTENT(OUT) :: utilout

!!$  !IMPORTANT: To use the cobb douglas utility for public consumption we have to compute E(qcons**(1-delta)/(1-delta)) in emaxfun
!!$  !cobb douglas utility for private and public consumption
!!$  utilout = pconsin**(1-gamma)/(1-gamma)+thetain*(qconsin)**(1-delta)/(1-delta)

  !ELNqconsin is computed correctly in emaxfuntemp and emaxfun
  IF (ABS(gamma-1d0) < small_no) THEN
     utilout = LOG(pconsin)+thetain*ELNqconsin
  ELSE
     utilout = pconsin**(1d0-gamma)/(1d0-gamma)+thetain*ELNqconsin
  END IF

!!$  IF (flag_here == 1) write(*,'(a,6f20.10)') 'utilout', utilout, pconsin, ELNqconsin, thetain, pconsin**(1-gamma)/(1-gamma), thetain*ELNqconsin
  
END SUBROUTINE utilfun
